export enum FileType {
  AVATAR = 'AVATAR',
  EXCEL = 'EXCEL',
  WORD = 'WORD',
  PDF = 'PDF',
  TXT = 'TXT',
  IMAGE = 'IMAGE',
  PPT = 'PPT',
  OTHER = 'OTHER',
}

export const parseFileType = ({ name }): FileType => {
  if (!name) {
    return FileType.OTHER;
  }
  const fileSuffix = name.substring(name.lastIndexOf('.')).toLowerCase();

  let result: FileType;
  switch (fileSuffix) {
    case '.xlsx':
    case '.xls':
      result = FileType.EXCEL;
      break;
    case '.docx':
    case '.doc':
      result = FileType.WORD;
      break;
    case '.pdf':
      result = FileType.PDF;
      break;
    case '.txt':
      result = FileType.TXT;
      break;
    case '.jpg':
    case '.jpeg':
    case '.gif':
    case '.png':
    case '.bmp':
      result = FileType.IMAGE;
      break;
    case '.ppt':
    case '.pptx':
      result = FileType.PPT;
      break;
    default:
      result = FileType.OTHER;
      break;
  }
  return result;
};
